package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo8 {
    public static void main(String[] args) {
        try(Connection connection= DBUtil.getConnection();){
            Statement statement = connection.createStatement();
            String sql="SELECT COUNT(*) count,c.name\n" +
                    "FROM class c\n" +
                    "JOIN student s ON c.id=s.class_id\n" +
                    "GROUP BY c.name";
            ResultSet rs=statement.executeQuery(sql);
            while(rs.next()){
                int count=rs.getInt("count");
                String name=rs.getString("c.name");
                System.out.println(name+"有"+count+"人");
            }
        }catch(SQLException e){
            e.printStackTrace();
        }
    }
}
